<?php
/**
 * GeoContexter
 * @link http://code.google.com/p/geocontexter/
 * @package GeoContexter
 */

/**
 * Get lists export file
 *
 * @package GeoContexter
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author Armand Turpel <geocontexter@gmail.com>
 * @version $Rev: 828 $ / $LastChangedDate: 2011-02-27 10:30:28 +0100 (So, 27 Feb 2011) $ / $LastChangedBy: armand.turpel $
 */

namespace Geocontexter\Controller;

use Zend\View\Model\ViewModel;
use Core\Controller\AbstractJsonController;
use Zend\View\Model\JsonModel;

class AjaxJsonGetListExportController extends AbstractJsonController
{
    public function indexAction()
    {
        $id_lists   = $this->request->getPost()->id_lists;

        if (($id_lists !== null) && is_array($id_lists)) {

          $ListExport = $this->CoreModel('ListExport');

          $params  = array('id_lists' => $id_lists);

          try {

            $export_file  = $ListExport->run( $params );

            return new JsonModel(array('file' => $export_file));

          } catch (\Exception $e) {

            $this->default_error = "Error\n File: " . __file__ . "\nLine: " . __line__ . "\nError: " . $e->getErrorString();

            return new JsonModel(json_encode(array('error' => $this->default_error)));

          }
/*
          if($export_file instanceof Mozend_ModelError)
          {
            $export_file->logError( __file__, __line__ );

            if ('development' == APPLICATION_ENV)
            {
               $this->default_error = "Error\n File: " . __file__ . "\nLine: " . __line__ . "\nError: " . $export_file->getErrorString();
            }

            $this->response->setBody(json_encode(array('error' => $this->default_error)));
          }
          else
          {
              $this->response->setBody(json_encode(array('file' => $export_file)));
          }

          */
        }
        else
        {
          $this->getResponse()->setContent(json_encode(array('error' => 'No group selected')));
        }

        //$this->sendResponse();


    }
}

